﻿#include "crashSuper.h"

crashRebate::crashRebate(double rebate) : moneyRebate(rebate) {}

CrashReturn::CrashReturn(double condition, double ret) : moneyCondition(condition), moneyReturn(ret) {}

double crashNormal::acceptCrash(double money)
{
    return money;
}

double crashRebate::acceptCrash(double money)
{
    return money * moneyRebate;
}

double CrashReturn::acceptCrash(double money)
{
    if (money >= moneyCondition)
        return money - int(money / moneyCondition) * moneyReturn;
    else
        return money;
}

double cashContext::getResult(double money)
{
    crashSuper* cash;
    switch (index)
    {
    case 0:
        cash = new crashNormal();
        break;
    case 1:
        cash = new crashRebate(0.8);
        break;
    case 2:
        cash = new CrashReturn(300, 100);
        break;
    }
    return cash->acceptCrash(money);
}
